function UserBcjkh() {
    this.form = this.InitForm();
    this.contrlInit();
    this.table = this.InitTable();
    // this.InitOrg();
}

UserBcjkh.prototype.contrlInit = function () {
    var year = $("#hidyear").val();
    var selectyear = 'dd[lay-value=' + year + ']';
    $('#year').siblings("div.layui-form-select").find('dl').find(selectyear).click();

    var month = $("#hidmonth").val();
    // console.log(month);
    // $("#weekmouth").val(month);
    var select = 'dd[lay-value=' + month + ']';
    $('#weekmouth').siblings("div.layui-form-select").find('dl').find(select).click();

}

UserBcjkh.prototype.InitForm = function () {
    var form;
    layui.use('form', function () {
        form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
        form.render();
    });
    return form;
}

//todo lzz
var col = [ // 表头
      {field: 'realname', title: '姓名', width: 120, align: 'center', fixed: 'left'}
    , {field: 'cardno', title: '身份证号', width: 180, align: 'center'}
    , {field: 'postnum', title: '职务工资', width: 100, align: 'center'}
    , {field: 'levnum', title: '级别工资', width: 100, align: 'center'}
    , {field: 'deptnum', title: '岗位工资', width: 100, align: 'center'}
    , {field: 'moneylevnum', title: '薪级工资', width: 100, align: 'center'}
    , {field: 'workerdeptnum', title: '机关工人岗位工资', width: 100, align: 'center'}
    , {field: 'stacnum', title: '结构工资', width: 100, align: 'center'}
    , {field: 'floatnum', title: '浮动工资', width: 100, align: 'center'}
    , {field: 'pelicenum', title: '警衔津贴', width: 100, align: 'center'}
    , {field: 'seasonnum', title: '节日补贴', width: 100, align: 'center'}
    , {field: 'oldnum', title: '养老医疗补贴', width: 100, align: 'center'}
    , {field: 'skillnum', title: '技术工人等级补贴', width: 100, align: 'center'}
    , {field: 'outernum', title: '远郊补助', width: 100, align: 'center'}
    , {field: 'skillevnum', title: '技术等级工资', width: 100, align: 'center'}
    , {field: 'superdeptnum', title: '特殊岗位奖励', width: 100, align: 'center'}
    , {field: 'lawsalarynum', title: '司法助理员津贴', width: 100, align: 'center'}
    , {field: 'csalarynum', title: '国家规定的津贴', width: 100, align: 'center'}
    , {field: 'bsalarynum', title: '基础津贴', width: 100, align: 'center'}
    , {field: 'livenum', title: '生活性补贴', width: 100, align: 'center'}
    , {field: 'overdutytimenum', title: '加值班费', width: 100, align: 'center'}
    , {field: 'workdeptnum', title: '工作性津贴（职务）', width: 100, align: 'center'}
    , {field: 'workyearnum', title: '工作性津贴（工作年限）', width: 100, align: 'center'}
    , {field: 'helpnum', title: '援助干部生活补贴', width: 100, align: 'center'}
    , {field: 'annum', title: '纪检监察人员办案补贴', width: 100, align: 'center'}
    , {field: 'teachernum', title: '教师（护士）提高1０％工资', width: 100, align: 'center'}
    , {field: 'pbhousenum', title: '公有住房提租补贴', width: 100, align: 'center'}
    , {field: 'citynum', title: '市级奖励', width: 100, align: 'center'}
    , {field: 'spnum', title: '特殊教育津贴', width: 100, align: 'center'}
    , {field: 'taxnum', title: '税务征收津贴', width: 100, align: 'center'}
    , {field: 'winnernum', title: '冬季取暖补贴', width: 100, align: 'center'}
    , {field: 'tellnum', title: '信访人员工作津贴', width: 100, align: 'center'}
    , {field: 'lawnum', title: '政法委机关工作津贴', width: 100, align: 'center'}
    , {field: 'yearnum', title: '年终绩效考核奖', width: 100, align: 'center'}
    , {field: 'teacheryearnum', title: '教（护）龄津贴', width: 100, align: 'center'}
    , {field: 'workleadernum', title: '工作性津贴（担任领导职务）', width: 100, align: 'center'}
    , {field: 'workpernum', title: '工作性津贴（年度绩效）', width: 100, align: 'center'}
    , {field: 'worklastnum', title: '工作性津贴剩余部分', width: 100, align: 'center'}
    , {field: 'retainnum', title: '保留津贴（补贴）', width: 100, align: 'center'}
    , {field: 'bshortimenum', title: '事业临时性补贴', width: 100, align: 'center'}
    , {field: 'dshortimenum', title: '机关临时性补贴', width: 100, align: 'center'}
    , {field: 'goodnum', title: '公务员优秀奖励', width: 100, align: 'center'}
    , {field: 'auditnum', title: '审计人员工作补贴', width: 100, align: 'center'}
    , {field: 'countrytechnum', title: '乡村教师岗位补贴', width: 100, align: 'center'}
    , {field: 'dutynum', title: '执勤岗位津贴', width: 100, align: 'center'}
    , {field: 'passwnum', title: '密码人员岗位津贴', width: 100, align: 'center'}
    , {field: 'casenum', title: '办案人员岗位津贴', width: 100, align: 'center'}
    , {field: 'deptsarynum', title: '岗位津贴', width: 100, align: 'center'}
    , {field: 'monthnum', title: '月绩效奖', width: 100, align: 'center'}
    , {field: 'examnum', title: '考核兑现奖', width: 100, align: 'center'}
    , {field: 'goalnum', title: '目标管理奖', width: 100, align: 'center'}
    , {field: 'safecheckenum', title: '安全生产监管监察岗位津贴', width: 100, align: 'center'}
    , {field: 'tephonenum', title: '通讯工具补贴', width: 100, align: 'center'}
    , {field: 'studynum', title: '上下班交通补贴', width: 100, align: 'center'}
    , {field: 'countrynum', title: '乡镇补贴', width: 100, align: 'center'}
    , {field: 'overtimenum', title: '加班补贴', width: 100, align: 'center'}
    , {field: 'comnum', title: '综合补助', width: 100, align: 'center'}
    , {field: 'yearonetimenum', title: '年终一次性奖金', width: 100, align: 'center'}
    , {field: 'othernum', title: '其他', width: 100, align: 'center'}
    , {field: 'other1num', title: '其他1', width: 100, align: 'center'}
    , {field: 'other2num', title: '其他3', width: 100, align: 'center'}
    , {field: 'other3num', title: '其他2', width: 100, align: 'center'}
    , {field: 'onechildnum', title: '独生子女费', width: 100, align: 'center'}
    , {field: 'reissuenum', title: '补发工资', width: 100, align: 'center'}
    , {field: 'benum', title: '应发工资', width: 100, align: 'center'}
    , {field: 'oldsafenum', title: '养老保险', width: 100, align: 'center'}
    , {field: 'deptsafenum', title: '机关事业养老保险', width: 100, align: 'center'}
    , {field: 'careeryearnum', title: '职业年金', width: 100, align: 'center'}
    , {field: 'birthnum', title: '生育保险', width: 100, align: 'center'}
    , {field: 'lostnum', title: '失业保险', width: 100, align: 'center'}
    , {field: 'hurtnum', title: '工伤保险', width: 100, align: 'center'}
    , {field: 'incomenum', title: '所得税', width: 100, align: 'center'}
    , {field: 'back1num', title: '补扣1', width: 100, align: 'center'}
    , {field: 'medicalnum', title: '医疗保险', width: 100, align: 'center'}
    , {field: 'incomebacknum', title: '应扣工资', width: 100, align: 'center'}
    , {field: 'workbacknum', title: '应扣工作性津贴', width: 100, align: 'center'}
    , {field: 'partybacknum', title: '扣会费', width: 100, align: 'center'}
    , {field: 'housebacknum', title: '住房公积金', width: 100, align: 'center'}
    , {field: 'performancenum', title: '应扣绩效工资', width: 100, align: 'center'}
    , {field: 'backsumnum', title: '扣发合计', width: 100, align: 'center'}
    , {field: 'payfornum', title: '实发工资', width: 100, align: 'center'}
]

UserBcjkh.prototype.InitTable = function () {

     //todo lzz
     // if(XXX!=0){
     //
     //     col.push({field: 'careeryearnum', title: '职业年金', width: 100, align: 'center'})
     // }


    var table;
    var _this = this;
    layui.use('table', function () {
        table = layui.table;
        table.render({
            elem: '#list'
            , height: $(window).height() - 100
            , url: 'get_userpay_list' // 数据接口
            , page: true // 开启分页
            , limit: 40
            , id: 'vtdpuserlist'
            , limits: [20, 40, 80, 100]
            , method: "post"
            , cols: [col]//todo lzz
            , request: {
                type: 'post'
            }
            , where: {
                year: $("#year").val(),
                month: $("#weekmouth").val(),
                orgid: $("#szdw").val(),
                realname: $("#realname").val(),
                status: $("#hidstatus").val()
            }
            , done: function (res, page, count) {
                var year = $("#year").val();
                var month = $("#weekmouth").val();
                var orgname = $.trim($("#szdw").find("option:selected").text());
                $("#title").html("(" + year + " 年  " + month + " 月)" + orgname + "在职工资表");
                var ressdate = res.data[0];
                var status = $("#hidstatus").val();

                console.log(status);
                console.log(ressdate);
                if (ressdate != null&&status==1) {
                    if (ressdate.postnum == 0 ) $("[data-field='postnum']").css('display', 'none');
                    if (ressdate.levnum == 0 ) $("[data-field='levnum']").css('display', 'none');
                    if (ressdate.deptnum == 0 ) $("[data-field='deptnum']").css('display', 'none');
                    if (ressdate.moneylevnum == 0 ) $("[data-field='moneylevnum']").css('display', 'none');
                    if (ressdate.workerdeptnum == 0 ) $("[data-field='workerdeptnum']").css('display', 'none');
                    if (ressdate.stacnum == 0 ) $("[data-field='stacnum']").css('display', 'none');
                    if (ressdate.floatnum == 0 ) $("[data-field='floatnum']").css('display', 'none');
                    if (ressdate.pelicenum == 0 ) $("[data-field='pelicenum']").css('display', 'none');
                    if (ressdate.seasonnum == 0 ) $("[data-field='seasonnum']").css('display', 'none');
                    if (ressdate.oldnum == 0 ) $("[data-field='oldnum']").css('display', 'none');
                    if (ressdate.skillnum == 0 ) $("[data-field='skillnum']").css('display', 'none');
                    if (ressdate.outernum == 0 ) $("[data-field='outernum']").css('display', 'none');
                    if (ressdate.skillevnum == 0 ) $("[data-field='skillevnum']").css('display', 'none');
                    if (ressdate.superdeptnum == 0 ) $("[data-field='superdeptnum']").css('display', 'none');
                    if (ressdate.lawsalarynum == 0 ) $("[data-field='lawsalarynum']").css('display', 'none');
                    if (ressdate.csalarynum == 0 ) $("[data-field='csalarynum']").css('display', 'none');
                    if (ressdate.bsalarynum == 0 ) $("[data-field='bsalarynum']").css('display', 'none');
                    if (ressdate.livenum == 0 ) $("[data-field='livenum']").css('display', 'none');
                    if (ressdate.overdutytimenum == 0 ) $("[data-field='overdutytimenum']").css('display', 'none');
                    if (ressdate.workdeptnum == 0 ) $("[data-field='workdeptnum']").css('display', 'none');
                    if (ressdate.workyearnum == 0 ) $("[data-field='workyearnum']").css('display', 'none');
                    if (ressdate.helpnum == 0 ) $("[data-field='helpnum']").css('display', 'none');
                    if (ressdate.annum == 0 ) $("[data-field='annum']").css('display', 'none');
                    if (ressdate.teachernum == 0 ) $("[data-field='teachernum']").css('display', 'none');
                    if (ressdate.pbhousenum == 0 ) $("[data-field='pbhousenum']").css('display', 'none');
                    if (ressdate.citynum == 0 ) $("[data-field='citynum']").css('display', 'none');
                    if (ressdate.spnum == 0 ) $("[data-field='spnum']").css('display', 'none');
                    if (ressdate.taxnum == 0 ) $("[data-field='taxnum']").css('display', 'none');
                    if (ressdate.winnernum == 0 ) $("[data-field='winnernum']").css('display', 'none');
                    if (ressdate.tellnum == 0 ) $("[data-field='tellnum']").css('display', 'none');
                    if (ressdate.lawnum == 0 ) $("[data-field='lawnum']").css('display', 'none');
                    if (ressdate.yearnum == 0 ) $("[data-field='yearnum']").css('display', 'none');
                    if (ressdate.teacheryearnum == 0 ) $("[data-field='teacheryearnum']").css('display', 'none');
                    if (ressdate.workleadernum == 0 ) $("[data-field='workleadernum']").css('display', 'none');
                    if (ressdate.workpernum == 0 ) $("[data-field='workpernum']").css('display', 'none');
                    if (ressdate.worklastnum == 0 ) $("[data-field='worklastnum']").css('display', 'none');
                    if (ressdate.retainnum == 0 ) $("[data-field='retainnum']").css('display', 'none');
                    if (ressdate.bshortimenum == 0 ) $("[data-field='bshortimenum']").css('display', 'none');
                    if (ressdate.dshortimenum == 0 ) $("[data-field='dshortimenum']").css('display', 'none');
                    if (ressdate.goodnum == 0 ) $("[data-field='goodnum']").css('display', 'none');
                    if (ressdate.auditnum == 0 ) $("[data-field='auditnum']").css('display', 'none');
                    if (ressdate.countrytechnum == 0 ) $("[data-field='countrytechnum']").css('display', 'none');
                    if (ressdate.dutynum == 0 ) $("[data-field='dutynum']").css('display', 'none');
                    if (ressdate.passwnum == 0 ) $("[data-field='passwnum']").css('display', 'none');
                    if (ressdate.casenum == 0 ) $("[data-field='casenum']").css('display', 'none');
                    if (ressdate.deptsarynum == 0 ) $("[data-field='deptsarynum']").css('display', 'none');
                    if (ressdate.monthnum == 0 ) $("[data-field='monthnum']").css('display', 'none');
                    if (ressdate.examnum == 0 ) $("[data-field='examnum']").css('display', 'none');
                    if (ressdate.goalnum == 0 ) $("[data-field='goalnum']").css('display', 'none');
                    if (ressdate.safecheckenum == 0 ) $("[data-field='safecheckenum']").css('display', 'none');
                    if (ressdate.tephonenum == 0 ) $("[data-field='tephonenum']").css('display', 'none');
                    if (ressdate.studynum == 0 ) $("[data-field='studynum']").css('display', 'none');
                    if (ressdate.countrynum == 0 ) $("[data-field='countrynum']").css('display', 'none');
                    if (ressdate.overtimenum == 0 ) $("[data-field='overtimenum']").css('display', 'none');
                    if (ressdate.comnum == 0 ) $("[data-field='comnum']").css('display', 'none');
                    if (ressdate.yearonetimenum == 0 ) $("[data-field='yearonetimenum']").css('display', 'none');
                    if (ressdate.othernum == 0 ) $("[data-field='othernum']").css('display', 'none');
                    if (ressdate.other1num == 0 ) $("[data-field='other1num']").css('display', 'none');
                    if (ressdate.other2num == 0 ) $("[data-field='other2num']").css('display', 'none');
                    if (ressdate.other3num == 0 ) $("[data-field='other3num']").css('display', 'none');
                    if (ressdate.onechildnum == 0 ) $("[data-field='onechildnum']").css('display', 'none');
                    if (ressdate.reissuenum == 0 ) $("[data-field='reissuenum']").css('display', 'none');
                    if (ressdate.benum == 0 ) $("[data-field='benum']").css('display', 'none');
                    if (ressdate.oldsafenum == 0 ) $("[data-field='oldsafenum']").css('display', 'none');
                    if (ressdate.deptsafenum == 0 ) $("[data-field='deptsafenum']").css('display', 'none');
                    if (ressdate.careeryearnum == 0 ) $("[data-field='careeryearnum']").css('display', 'none');
                    if (ressdate.birthnum == 0 ) $("[data-field='birthnum']").css('display', 'none');
                    if (ressdate.lostnum == 0 ) $("[data-field='lostnum']").css('display', 'none');
                    if (ressdate.hurtnum == 0 ) $("[data-field='hurtnum']").css('display', 'none');
                    if (ressdate.incomenum == 0 ) $("[data-field='incomenum']").css('display', 'none');
                    if (ressdate.back1num == 0 ) $("[data-field='back1num']").css('display', 'none');
                    if (ressdate.medicalnum == 0 ) $("[data-field='medicalnum']").css('display', 'none');
                    if (ressdate.incomebacknum == 0 ) $("[data-field='incomebacknum']").css('display', 'none');
                    if (ressdate.workbacknum == 0 ) $("[data-field='workbacknum']").css('display', 'none');
                    if (ressdate.partybacknum == 0 ) $("[data-field='partybacknum']").css('display', 'none');
                    if (ressdate.housebacknum == 0 ) $("[data-field='housebacknum']").css('display', 'none');
                    if (ressdate.performancenum == 0 ) $("[data-field='performancenum']").css('display', 'none');
                    if (ressdate.backsumnum == 0 ) $("[data-field='backsumnum']").css('display', 'none');
                    if (ressdate.payfornum == 0 ) $("[data-field='payfornum']").css('display', 'none');
                }
            }
        });
    });
    return table;
}

UserBcjkh.prototype.searchtable = function () {
    this.table.reload('vtdpuserlist', {
        page: {
            curr: 1 //重新从第 1 页开始
        }
        , where: {
            year: $("#year").val(),
            month: $("#weekmouth").val(),
            orgid: $("#szdw").val(),
            realname: $("#realname").val()
        }
    });
}

UserBcjkh.prototype.import = function () {
    var year = $("#year").val();
    var month = $("#weekmouth").val();
    top.mylayui.open({
        type: 2,
        title: "工资表导入",
        shadeClose: true,
        shade: 0.5,
        area: ['680px', '400px'],
        content: 'payass/user_pay_list_import?year=' + year + '&month=' + month
    });

}

UserBcjkh.prototype.export = function () {
    top.ShowZheZhao();
    var year = $("#year").val();
    var month = $("#weekmouth").val();
    $.ajax({
        type: "POST",
        url: "user_pay_export_person",
        data: {year: year, month: month},
        beforeSend: function (XHR) {

        },
        success: function (data) {
            data = eval('(' + data + ')');
            if (data.result > 0) {
                window.open(data.msg, '_self');
            }
            else {
                top.mylayui.msg(data.msg, {icon: 0});
            }
        },
        complete: function (XHR) {
            top.ShowZheZhao();
        },
        error: function () {
        }
    });
}

UserBcjkh.prototype.addresult = function (result, msg) {
    if (result > 0) {
        top.mylayui.msg('操作成功', {icon: 1});
        top.mylayui.closeAll('iframe');
        vUserPayPerson.searchtable();
    }
    else {
        if (msg) {
            top.mylayui.msg(msg, {icon: 0});
        } else {
            top.mylayui.msg('操作失败', {icon: 0});
        }
    }
}


var vUserPayPerson;
$(function () {
    vUserPayPerson = new UserBcjkh();
})